package com.wang.example.aio.server;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.AsynchronousServerSocketChannel;


public class AioServerHandler implements Runnable {

    /*进行异步通信的通道*/
    public AsynchronousServerSocketChannel channel;

    public AioServerHandler(int port) {
        try {
            //创建服务端通道
            channel = AsynchronousServerSocketChannel.open();
            //绑定端口
            channel.bind(new InetSocketAddress(port));
            System.out.println("Server is start,port:"+port);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @Override
    public void run() {
        //用于接收客户端的连接，异步操作，
        // 需要实现了CompletionHandler接口的处理器处理和客户端的连接操作
        channel.accept(this,new AioAcceptHandler());
    }

}
